var vm = new Vue({
	el: '#app',
	data: {
		env:'prod',//当前环境 dev为本地测试环境所有API接口数据皆为测试机绝对路径 prod为线上环境API接口为相对路径
		form: {
			uaid:'',//保存时必须的ID参数
			name:'',//姓名
			department: '',//部门
			type:'',//类型
			banji:'',//班级
			zhuanye:'',//专业
			account:'',//学工号
			sex:'',//性别
			info:'此电子ID为师生进出校门身份识别专用，请勿截图给他人使用。（待师生人脸识别照片库建成后将补上照片）',
			img:''
		}
	},
	created() {
		this.form.uaid = this.getURLParameter('uaid')||'';
		if(this.form.uaid.length>0){
			this.getUserInfo();
		}else{
			this.$dialog.alert({
				title: '警告',
				message: '缺少用户参数'
			}).then(() => {});
		}
	},
	methods: {
		getAxiosUrl(url,mode){//动态返回当前请求链接 mode=dev时为本地环境使用测试机绝对路径 mode=prod时为线上环境使用相对路径
			if(url){
				if(mode=='dev'){
					return 'http://106.52.234.116:6060/f/'+url;
				}else if(mode=='prod'){
					return './'+url;
				}else{
					return url;
				}
			}else{
				return '';
			}
		},
		getUserInfo() { //获取用户信息
			this.loading = this.$toast.loading({duration: 0,forbidClick:true,overlay:true,message:'加载中...'});
			axios.get(this.getAxiosUrl('getLoginUserData',this.env),{params:{uaid:this.form.uaid}}).then(x => {
				this.loading.clear();
				if(x.data.ok){
					this.form.name = x.data.data.name;
					this.form.department = x.data.data.department;
					this.form.type = x.data.data.type;
					this.form.banji = x.data.data.banji;
					this.form.zhuanye = x.data.data.zhuanye;
					this.form.account = x.data.data.account;
					this.form.sex = x.data.data.sex;
					this.form.img = `${location.origin}/userfiles/id/photos/${x.data.data.enid}.jpg`;
				}else{
					console.log(x.data.message);
					this.$dialog.alert({
						title: '警告',
						message: x.data.message,
					}).then(() => {});
				}
			}).catch(e=>{
				console.log(e);
				this.loading.clear();
				this.$toast.fail('数据获取失败');
			})
		},
		getURLParameter(name) {//从URL中获取参数
		  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
		},
	}
})